#include <iostream>

using namespace std;

void f()
{
	static int n=1; // static int n;
	
	int x=1; // int x;
	
	cout<< "n=" << n++;
	cout<< ",";
	cout<< " x=" << x++ << endl; 
}

void f2 ( )
{
	static int n; // static int n; 默认值为0
	int x; // int x;
	cout<< "n=" << n++;
	cout<< ",";
	cout<< " x=" << x++ << endl; 
}

class X {
	int i;

public:
	X(int ii = 0) : i(ii) { 
		cout << "X():" << i << endl;
	} // Default
	
	~X() {
		cout << "~X():" << i << endl;
	}
};

void f3() {
	static X x1(47);
	static X x2; // Default constructor required
}


int main(int argc, char *argv[]) {
	
	/*
		函数内的static变量：
		1、static变量n -- 只被初始化一次
		2、f()函数间，共享一个n
	*/
	f(); 
	f();
	cout << "====================" << endl;
	// 对static变量n -- 自动赋0值
	f2();
	f2();
	
	cout << "====================" << endl;
	// static修饰的对象，只会被创建一次 -- 在f3()之间共享
	// 程序运行完之后才销毁
	f3();
	f3();
}